// 开发工具：用于测试Cookie横幅
// 在浏览器控制台中使用这些函数

declare global {
  interface Window {
    cookieUtils: {
      showBanner: () => void;
      hideBanner: () => void;
      clearAll: () => void;
      getStatus: () => void;
      acceptAll: () => void;
      acceptNecessary: () => void;
    };
  }
}

// Cookie测试工具
export const CookieTestUtils = {
  // 强制显示Cookie横幅（清除当前设置）
  showBanner: () => {
    localStorage.removeItem('cookie-consent');
    localStorage.removeItem('cookie-preferences');
    window.location.reload();
    console.log('Cookie banner will be shown after page reload');
  },

  // 隐藏Cookie横幅（设置为已接受）
  hideBanner: () => {
    localStorage.setItem('cookie-consent', 'accepted');
    localStorage.setItem('cookie-preferences', JSON.stringify({
      necessary: true,
      analytics: true,
      marketing: true,
      functional: true
    }));
    console.log('Cookie banner hidden');
  },

  // 清除所有Cookie设置
  clearAll: () => {
    localStorage.removeItem('cookie-consent');
    localStorage.removeItem('cookie-preferences');
    console.log('All cookie settings cleared');
  },

  // 获取当前状态
  getStatus: () => {
    const consent = localStorage.getItem('cookie-consent');
    const preferences = localStorage.getItem('cookie-preferences');
    
    console.log('Cookie status:', {
      consent,
      preferences: preferences ? JSON.parse(preferences) : null,
      hasConsent: consent !== null
    });
  },

  // 快速接受所有Cookie
  acceptAll: () => {
    localStorage.setItem('cookie-consent', 'accepted');
    localStorage.setItem('cookie-preferences', JSON.stringify({
      necessary: true,
      analytics: true,
      marketing: true,
      functional: true
    }));
    console.log('All cookies accepted');
  },

  // 快速设置为仅必要Cookie
  acceptNecessary: () => {
    localStorage.setItem('cookie-consent', 'necessary-only');
    localStorage.setItem('cookie-preferences', JSON.stringify({
      necessary: true,
      analytics: false,
      marketing: false,
      functional: false
    }));
    console.log('Set to essential cookies only');
  }
};

// 在开发环境中将工具暴露到全局
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'development') {
  window.cookieUtils = CookieTestUtils;
  console.log('Cookie testing tools loaded. Use window.cookieUtils to access the following methods:');
  console.log('- showBanner(): Show cookie banner');
  console.log('- hideBanner(): Hide cookie banner'); 
  console.log('- clearAll(): Clear all settings');
  console.log('- getStatus(): View current status');
  console.log('- acceptAll(): Accept all cookies');
  console.log('- acceptNecessary(): Accept essential cookies only');
}
